use bincode::{Decode, Encode};
use serde::de::DeserializeOwned;
use serde::Serialize;
use crate::codec::RpcEncode;
use crate::{encode, RpcContext, RpcResult};

macro_rules! impl_rpc_encode {
    ($($t: ident),*) => {
        $(
            impl RpcEncode for $t {
                fn encode(&self, context: &RpcContext) -> RpcResult<Vec<u8>> {
                    encode(context, self)
                }
            }
        )*
    };
}

// impl_rpc_encode!(i8, i16, i32, i64, u8, u16, u32, u64, isize, usize, String);
// impl_rpc_encode!(bool, f32, f64, char);

// impl <T: Decode<()> + Encode + DeserializeOwned + Serialize + 'static> RpcEncode for Option<T> {
//     fn encode(&self, context: &RpcContext) -> RpcResult<Vec<u8>> {
//         encode(context, self)
//     }
// }

impl <T: Decode<()> + Encode + DeserializeOwned + Serialize + 'static> RpcEncode for T {
    fn encode(&self, context: &RpcContext) -> RpcResult<Vec<u8>> {
        encode(context, self)
    }
}